package com.ty.tour.controller;


import com.ty.tour.common.utils.ReturnData;
import com.ty.tour.pojo.Attractions;
import com.ty.tour.service.AttractionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * @Description: 旅游景点Controller
 * @Author: xiexiaoping
 * @Date: 2020/3/21 9:22
 **/
@Api(value = "旅游景点", tags = "旅游景点查看")
@RestController
@RequestMapping("/attractions")
public class AttractionsController {

    @Autowired
    private AttractionsService attractionsService;

    /***
     * @MethodName: getAttractionByCusId
     * @Description: 获取定制类型对应景点信息
     * @Param: [customId]
     * @Return: com.ty.tour.common.utils.ReturnData
     * @Author: xiexiaoping
     * @Date: 2020/3/21 9:27
     **/
    @PostMapping("/attractionCustom")
    @ApiOperation(value = "获取定制类型对应景点", notes = "旅游景点实体")
    public ReturnData getAttractionByCusId(Integer customId) {
        final ReturnData returnData = new ReturnData();
        try {
            if (customId == null) {
                return returnData.fail();
            }
            List<Attractions> attractions = attractionsService.getAttractionBycusId(customId);
            if (attractions.size() < 1) {
                return returnData.fail();
            }
            return returnData.success(attractions, 1);
        } catch (Exception e) {
            e.printStackTrace();
            return returnData.fail();
        }
    }

    /***
     * @MethodName: getAttractionByLevel
     * @Description: 根据景点推荐等级搜索景点信息
     * @Param: []
     * @Return: com.ty.tour.common.utils.ReturnData
     * @Author: xiexiaoping
     * @Date: 2020/3/21 9:55
     **/
    @PostMapping("/attractionLevel")
    @ApiOperation(value = "根据景点推荐等级搜索景点信息", notes = "旅游景点实体")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "景点推荐等级", name = "level", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(value = "关键字搜索", name = "keyword", dataType = "String", paramType = "query", required = false)
    })
    public ReturnData getAttractionByLevel(Integer level, String keyword) {
        final ReturnData returnData = new ReturnData();
        try {
            List<Attractions> attractions = attractionsService.getAttractionByLevel(level, keyword);
            return returnData.success(attractions, 1);
        } catch (Exception e) {
            e.printStackTrace();
            return returnData.fail();
        }
    }

    /***
     * @MethodName: getAttrtionsById
     * @Description: 获取景点详情
     * @Param: []
     * @Return: com.ty.tour.common.utils.ReturnData
     * @Author: xiexiaoping
     * @Date: 2020/3/21 10:30
     **/
    @PostMapping("/attrtionsById")
    @ApiOperation(value = "查看景点详细信息", notes = "旅游景点实体")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "景点编号", name = "id", dataType = "Integer", paramType = "query", required = true)
    })
    public ReturnData getAttrtionsById(Integer id) {
        final ReturnData returnData = new ReturnData();
        try {
            Attractions attractions = attractionsService.getById(id);
            return returnData.success(attractions, 1);
        } catch (Exception e) {
            e.printStackTrace();
            return returnData.fail();
        }
    }
}
